<template>
	<view>
		<van-cell title="姓名" :value="dataDetail.name"/>
		<van-cell title="电话" :value="dataDetail.tel"/>
		<van-cell title="科室" :value="dataDetail.partmentName"/>
		<van-cell title="角色" :value="dataDetail.zRoles"/>
		<van-cell title="工号" :value="dataDetail.jobNumber"/>
		<!-- <van-cell title="验证码" :value="userinfo.vtfyCode"/> -->
		
		<view style="display: flex; flex-flow: row;justify-content: space-around;margin-top: 50px;">
			<van-button plain :color="primaryColor" @click="onAgreeReq">通过申请</van-button>
			<van-button plain type="danger" @click="onDisAgreeReq">拒绝申请</van-button>
		</view>
		
		<van-dialog id="van-dialog" />
		<van-toast id="van-toast" />
	</view>
</template>

<script>
	import Toast from '@/wxcomponents/toast/toast'
	import Dialog from '@/wxcomponents/dialog/dialog'
	import utils from '@/common/utils.js'
	export default {
		data() {
			return {
				primaryColor:getApp().globalData.primaryColor,
				dataDetail: Object,
				roleList: []
			}
		},
		async onLoad(options) {
			const temp = JSON.parse(decodeURIComponent(options.data))
			this.roleList = await this.getRoles()
			temp.zRoles = this.roleList.filter(o => temp.roles.includes(o.value)).map(o => o.label).join(',')
			this.dataDetail = temp
		},
		methods: {
			async getRoles(){
				return await utils.req('/config/getRoles',{token:'1'})
			},
			async onDisAgreeReq(){
				Dialog.confirm({
					title: '提示',
					message: '确认拒绝申请?'
				}).then(async() => {
					try{
						uni.showLoading({
							mask:true,
							title:'上传数据中...'
						})
						const reqData = {}
						reqData.token = uni.getStorageSync('userinfo').token
						reqData.user = {
							userId: this.dataDetail.userId,
							userStatus: 'registFail'
						}
						await utils.req('/user/updateUser', reqData)
						uni.navigateBack({
							delta:1
						})
					}catch(e){
						console.error(e)
						Toast(e.msg)
					}finally{
						uni.hideLoading()
					}
				}).catch(() => {
					// on cancel
				});
			},
			async onAgreeReq(){
				Dialog.confirm({
					title: '提示',
					message: '确认通过申请?'
				}).then(async() => {
					try{
						uni.showLoading({
							mask:true,
							title:'上传数据中...'
						})
						const reqData = {}
						reqData.token = uni.getStorageSync('userinfo').token
						reqData.user = {
							userId: this.dataDetail.userId,
							userStatus: 'normal'
						}
						await utils.req('/user/updateUser', reqData)
						uni.navigateBack({
							delta:1
						})
					}catch(e){
						console.error(e)
						Toast(e.msg)
					}finally{
						uni.hideLoading()
					}
				}).catch(() => {
					// on cancel
				});
			}
		}
	}
</script>

<style scoped lang="scss">

</style>
